package gamecode;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;
import java.util.Random;

public class EntityStar extends Entity {

	private Color starColor;
	
	public EntityStar(Color c, DPoint pos) {
		starColor = c;
		this.setPosition(pos);
	}
	
	public void update(Rectangle bounds, EntityPlayerShip player) {
		Random rnd = new Random();
		if(this.getPosition().getX() < (player.getPosition().getX()-bounds.getWidth()/2)) {
			this.setPosition(new DPoint(player.getPosition().getX()+bounds.getWidth()/2, (rnd.nextDouble()*bounds.getHeight())+(player.getPosition().getY()-bounds.getHeight()/2)));
		}
		else if(this.getPosition().getX() > (player.getPosition().getX()+bounds.getWidth()/2)) {
			this.setPosition(new DPoint(player.getPosition().getX()-bounds.getWidth()/2, (rnd.nextDouble()*bounds.getHeight())+(player.getPosition().getY()-bounds.getHeight()/2)));
		}
		else if(this.getPosition().getY() < (player.getPosition().getY()-bounds.getHeight()/2)) {
			this.setPosition(new DPoint((rnd.nextDouble()*bounds.getWidth())+(player.getPosition().getX()-bounds.getWidth()/2), player.getPosition().getY()+bounds.getHeight()/2));
		}
		else if(this.getPosition().getY() > (player.getPosition().getY()+bounds.getHeight()/2)) {
			this.setPosition(new DPoint((rnd.nextDouble()*bounds.getWidth())+(player.getPosition().getX()-bounds.getWidth()/2), player.getPosition().getY()-bounds.getHeight()/2));
		}
	}
	
	public void drawEntity(Graphics g, Rectangle bounds, EntityPlayerShip player) {
		g.setColor(starColor);
		g.drawOval((int)(this.getPosition().getX() + (bounds.getWidth()/2 - player.getPosition().getX())), (int)(this.getPosition().getY() + (bounds.getHeight()/2 - player.getPosition().getY())), 1, 1);
	}
}